package com.luo.demo;

import com.alibaba.fastjson.JSON;
import com.luo.mapper.UserMapper;
import com.luo.pojo.Score;
import com.luo.pojo.UserScore;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;

@WebServlet("/homePageSelectScoreServlet")
public class homePageSelectScore extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id =req.getParameter("id");
        SqlSession session = util00.useSqlSessionFactory().openSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<UserScore> scoreList = mapper.selectScore(id);

        String jsonStr = JSON.toJSONString(scoreList);
        resp.setContentType("text/json;charset=utf-8");
        resp.getWriter().write(jsonStr);

        session.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
